package com.fanfanwang.ffw.app.fragment;

import java.net.URLDecoder;
import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.fanfanwang.ffw.app.AppManager;
import com.fanfanwang.ffw.app.adapter.GlyCarportStatusAdapter;
import com.fanfanwang.ffw.app.base.BaseFragment;
import com.fanfanwang.ffw.app.bean.CarportBean;
import com.fanfanwang.ffw.app.tenant.R;
import com.fanfanwang.ffw.app.tools.SharedPreferencesUtil;
import com.fanfanwang.ffw.app.ui.login.LoginAct;
import com.fanfanwang.ffw.app.ui.my.AccountAndSafetyAct;
import com.fanfanwang.ffw.app.ui.my.GlyMyCarportManagementAct;
import com.fanfanwang.ffw.app.ui.my.MyUpdateInfoAct;
import com.fanfanwang.ffw.app.widget.CommonTitleBar;

@SuppressLint("ValidFragment")
public class GlyMyFragment extends BaseFragment {
	private LayoutInflater inflater;
	private CommonTitleBar commonTitleBar;
	private Context context;
	private int i=0;//0表示第一个显示，1表示第二个显示，2表示第三个fragement显示。
	//停车场名字，停车场笛子，经营人，所属片区，
	private TextView tv_carport_name,tv_carport_add,set_jingyignren,set_belong_dist;
	private RelativeLayout rl_carport_management;
	private Intent mIntent;
	private RelativeLayout rl_my_exit;
	@SuppressLint("ValidFragment")
	public GlyMyFragment(Context context) {
		// TODO Auto-generated constructor stub
		super();
		inflater = LayoutInflater.from(context);
		this.context=context;
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View settingLayout = inflater.inflate(
				R.layout.gly_activity_my, container, false);
		return settingLayout;
	}
	public static GlyMyFragment getGlyMyFragment(Context context) {

		GlyMyFragment  mainMyFragment = new GlyMyFragment(context);
		return mainMyFragment;
	}
	@SuppressLint("NewApi")
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		getActivity().getWindow().setFormat(PixelFormat.TRANSLUCENT);
		initView(view);
		initData();
		setListener();
	}

	@Override
	public void initView(View view) {
		commonTitleBar = (CommonTitleBar) view.findViewById(R.id.common_titlebar);
		tv_carport_name=(TextView)view.findViewById(R.id.tv_carport_name);
		tv_carport_add=(TextView)view.findViewById(R.id.tv_carport_add);
		set_jingyignren=(TextView)view.findViewById(R.id.set_jingyignren);
		set_belong_dist=(TextView)view.findViewById(R.id.set_belong_dist);
		rl_carport_management=(RelativeLayout)view.findViewById(R.id.rl_carport_management);
		rl_my_exit=(RelativeLayout)view.findViewById(R.id.rl_my_exit);
	}

	@Override
	public void initData() {
		commonTitleBar.setCenterText(getString(R.string.main_tab_my));
		String name=SharedPreferencesUtil.getInstance(getActivity()).getName();
		if(!TextUtils.isEmpty(name)){
			tv_carport_name.setText(name);
		}
		String address=SharedPreferencesUtil.getInstance(getActivity()).getAddress();
		if(!TextUtils.isEmpty(address)){
			tv_carport_add.setText(address);
		}
		String jingyingren=SharedPreferencesUtil.getInstance(getActivity()).getTransactor();
		if(!TextUtils.isEmpty(jingyingren)){
			set_jingyignren.setText(jingyingren);
		}
		String pianqu=SharedPreferencesUtil.getInstance(getActivity()).getPainqu();
		if(!TextUtils.isEmpty(pianqu)){
			set_belong_dist.setText(pianqu);
		}

	}
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}
	/**
	 *  提示对话框
	 * @param message
	 */
	public void showLogoutDialog(String message){
		new AlertDialog.Builder(context).setTitle(getString(R.string.exit_title))  
		.setMessage(message)
		.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialog, int which) {
				//sharedPreferencesUtil.putIsLogin(false);
				SharedPreferencesUtil.getInstance(getActivity()).putParkingId(null);
				SharedPreferencesUtil.getInstance(getActivity()).putTransactor(null);
				SharedPreferencesUtil.getInstance(getActivity()).putPianqu(null);
				SharedPreferencesUtil.getInstance(getActivity()).putChargetype(null);
				SharedPreferencesUtil.getInstance(getActivity()).putChargeprice(null);
				SharedPreferencesUtil.getInstance(getActivity()).putName(null);
				SharedPreferencesUtil.getInstance(getActivity()).putAddress(null);
				SharedPreferencesUtil.getInstance(getActivity()).putParktype(null);
				SharedPreferencesUtil.getInstance(getActivity()).putOpentime(null);
				AppManager.getAppManager().finishAllActivity();
				Intent mIntent = new Intent(getActivity(), LoginAct.class);
				startActivity(mIntent);
				getActivity().finish();
			}
		})
		.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		})
		.show();
	}
	@Override
	public void setListener() {
		rl_carport_management.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mIntent=new Intent(getActivity(), GlyMyCarportManagementAct.class);
				startActivity(mIntent);
			}
		});
		rl_my_exit.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showLogoutDialog(getString(R.string.exit_info));
			}
		});

	}

}
